import NewsIndexModel from '@/models/newsIndex';
import IndexModel from '@/models/newsIndex';
import SlideShowModel from '@/models/slideShow';
import newsService from '@/services/newsService';
import slideShowService from '@/services/slideShowService';
import { action, computed, observable } from 'mobx';

export default class NewsStore {
    //图片地址
    @observable
    imageURL: string = 'https://image.xiaokesi.com/';
    @observable
    pageSize?: number = 5;
    @observable
    pageNumber?: number = 1;
    @observable
    title?: string;
    @observable
    organizer?: string;
    @observable
    startTime?: string;
    @observable
    endTime?: string;
    @observable
    newsList?: Array<NewsIndexModel>;
    @observable
    newsListLoading: boolean = false;
    @observable
    id?: number;
    @observable
    newsInfo?: NewsIndexModel;
    @observable
    newsInfoLoading: boolean = false;

    @observable
    slideShowListUp?: SlideShowModel[];
    @observable
    slideShowListDown?: SlideShowModel[];
    static title: undefined;


    @action
    async infoNews(id: any) {
        this.newsInfoLoading = true;
        this.newsInfo = (await newsService.info(id)).dataInfo;
        this.newsInfoLoading = false;
    }
    @action
    async listNews() {
        this.newsListLoading = true;
        let option = {
            pageNumber: this.pageNumber,
            pageSize: this.pageSize,
            title: this.title,
            organizer: this.organizer,
            startTime: this.startTime,
            endTime: this.endTime,

        };
        this.newsList = (await newsService.list(option)).dataList;
        this.newsListLoading = false;
        console.log(this.newsList);

    }
    @action
    async list1() {
        this.newsListLoading = true;
        let option = {
            pageNumber: this.pageNumber,
            pageSize: this.pageSize,


        };
        this.newsList = (await newsService.list1(option)).dataList;
        this.newsListLoading = false;
        console.log(this.newsList);

    }
    /**
     * 首页轮播图列表
     */

    @action
    async getCarouselListUp() {
        this.slideShowListUp = (await slideShowService.slideShowList({ type: 0 })).dataList;
        console.log(this.slideShowListUp);

    }
    @action
    async getCarouselListDown() {
        this.slideShowListDown = (await slideShowService.slideShowList({ type: 1 })).dataList;
        console.log(this.slideShowListDown);

    }
}

export const newsStore = new NewsStore();
